import{Mongoose,Schema,Model,Document} from 'mongoose';
import { BaseDao} from './BaseDao';
import{ User} from '../models/User';
export class UsersDao extends BaseDao
{
  userModel:Model<any>;
  constructor(){
    super();
    this.userModel = this.dbManager.getModel("mUser");
  }
  add(user:User,callback)
  {
    var user_ = new this.userModel(user);
    user_.save(callback);
  }
  get(username:string,password:string,callback)
  {
    this.userModel.findOne({username:username,password:password},callback);
  }
  update(user:User,callback)
  {
    var query = {_id:user._id};
    var updater = {
      nickname:user.nickname,
      password:user.password,
      avatar:user.avatar
    }
    this.userModel.update(query,updater,()=>{
      this.userModel.findById(user._id,callback);
    });
  }
}
